package by.parfen.messages.webapp.app;

import org.apache.wicket.Session;
import org.apache.wicket.authroles.authentication.AuthenticatedWebSession;
import org.apache.wicket.authroles.authorization.strategies.role.Roles;
import org.apache.wicket.injection.Injector;
import org.apache.wicket.request.Request;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import by.parfen.messages.services.ver2.Client;
import by.parfen.messages.services.ver2.Server;

public class BasicAuthenticationSession extends AuthenticatedWebSession {

	private static final Logger LOGGER = LoggerFactory.getLogger(BasicAuthenticationSession.class);

	public static final String ROLE_SIGNED_IN = "SIGNED_IN";

	private Roles resultRoles;

	private Client client;
	private Server server;

	public BasicAuthenticationSession(final Request request) {
		super(request);
		Injector.get().inject(this);
	}

	public static BasicAuthenticationSession get() {
		return (BasicAuthenticationSession) Session.get();
	}

	@Override
	public boolean authenticate(final String userName, final String password) {
		boolean authenticationResult = false;
		authenticationResult = true;
		// final UserAccount account =
		// userAccountService.getAccountByEmail(userName);
		// if (account != null && account.getPassw().equals(password)) {
		// initFieldsByAccount(account);
		// authenticationResult = true;
		// }
		return authenticationResult;
	}

	@Override
	public Roles getRoles() {
		if (isSignedIn() && (resultRoles == null)) {
			resultRoles = new Roles();
			// AppRole role = userAccountService.getRole(user.getId());
			// if (role != null) {
			// resultRoles.add(role.name());
			// }
		}
		return resultRoles;
	}

	@Override
	public void signOut() {
		super.signOut();
	}

	public Client getClient() {
		return client;
	}

	public void setClient(Client client) {
		this.client = client;
	}

	public Server getServer() {
		return server;
	}

	public void setServer(Server server) {
		this.server = server;
	}

}
